from Auto_Code import case
from ruamel import yaml
from Auto_Code import CaseCollection

class case_action(case.case):
    @staticmethod
    def read_search_path(yaml_path):
        """
        读取search_path属性
        :param yaml_path:小case文件路径
        :return:
        """
        ya=yaml.YAML()
        with open(yaml_path,'r') as f:
            tmp_dict=ya.load(f)
            if tmp_dict.get(case_action.description_str).get(case_action.search_path_str):
                return tmp_dict[case_action.description_str][case_action.search_path_str]
            else:
                return False


class casecollection_action(CaseCollection.CaseCollection):
    @staticmethod
    def read_small_case_path(yaml_path):
        """
        读取小用例路径
        :param yaml_path:总用例路径
        :return:
        """
        ya = yaml.YAML()
        count=1
        return_dic=[]
        with open(yaml_path, 'r') as f:
            tmp_dict = ya.load(f)
            while(True):
                if tmp_dict.get(count):
                    if tmp_dict[count].get(casecollection_action.path_str):
                        return_dic.append(tmp_dict[count][casecollection_action.path_str])
                        count+=1
                else:
                    #数字超过则break
                    break
            return return_dic